<?php

defined('SYSPATH') or die('No direct script access.');

class Controller_Home_Rate extends Controller_Portal {

    public function action_rate() {
        
        $this->template->content = View::factory('home/rate');
    }

    public function action_gallery() {
        $this->add_css(array('customSelectBox'));
        $this->add_js(array('SelectBox_1'));
        
        $s_submission = new Model_Service_Submission();
        
        $a_pagination = Kohana::$config->load("pagination");
        $page = Arr::get($_GET, 'page') == "" ? 1 : Arr::get($_GET, 'page');
        $items_per_page = 8;
        $to = $page * $items_per_page;
        $offset = $to - $items_per_page;
        $sort = null;
        $s = Arr::get($_REQUEST, 's','created');
        if($s == 'created'){
            $sort = array('created'=>'desc');
        }else{
            $sort = array('vote'=>'desc');
        }
        $a_pagination->admin["portal"] = $items_per_page;

        $a_submission = $s_submission->load_all(false, $offset, $items_per_page, null, $sort);
        
        $count_all = $s_submission->load_all(true);
      
        Arr::set_path($a_pagination, 'portal.total_items', $count_all);
        $pagination = new Pagination(Arr::get($a_pagination, 'portal'));

        $this->template->content = View::factory('home/gallery')
                ->set('a_submission', $a_submission)
                ->set('pagination', $pagination);
    }

}
